public class demo {
    public void addIndex(int index,int data){

        ListNode node = new ListNode(data);

        if (index < 0 || index >size()){
            System.out.println("位置不合法！");
            return;
        }
        if (index == 0){
            addFirst(data);
            return;
        }
        if (index == size()){
            addLast(data);
            return;
        }
        ListNode cur = head;
        while (index - 1 != 0){
            cur = cur.next;
            index--;
        }
        node.next = cur.next;
        cur.next = node;

    }
}
